#include "Customer_Obj.h"
#include <iostream>
#include <fstream>
#include <cassert>

using namespace std;
using std::ifstream;

int randNumGen(int,int);

//Utility random number generator function
int randNumGen(int min,int max) {
        srand(rand());      //This is not needed. It works fine without it. I think.
        //cout << (rand()%max)+min;
        return((rand()%max)+min);
}

Customer_Obj::Customer_Obj() {
		//initialize customer to empty
        ArrivalTime= -1;
        actionTime= 0;
        lineProcessTime=0;
        fName="";
        lName="";
        inDeli = false;
        inSweeps = false;
        sweepsChoose = false;
        deliChoose = false;

}

void Customer_Obj::setFirstName() {
	//first name is set from picking random element from firstNames array
    int randomNumber = randNumGen(1,120);
    fName=firstNames[randomNumber];
}

string Customer_Obj::getFirstName() {
        return(fName);

}
void Customer_Obj::setLastName() {
	//last name is set from picking random element from lastNames array
    int randomNumber = randNumGen(1,100);
    lName=lastNames[randomNumber];
}

string Customer_Obj::getLastName() {
        return(lName);
}
Time Customer_Obj::getTimeInStore() {
//TODO
}

void Customer_Obj::setArrivalTime() {
		//set arrivalTime from 1 to 1440
        ArrivalTime = randNumGen(1,1440);
}
int Customer_Obj::getArrivalTime() {
        return(ArrivalTime);
}

void Customer_Obj::setPayType(){
		//according to given statistics randomly give each customer their pay type
        int randomNumber = randNumGen(1,10);
        if(randomNumber>0 && randomNumber <= 7)
                payCredit=true;
        if(randomNumber == 8 || randomNumber == 9 )
                payCash=true;
        else
                payCheck=true;
}

string Customer_Obj::getPayType() {
        if(payCredit)
                return("Credit");
        if(payCash)
                return("Cash");
        if(payCheck)
                return("Check");
}

void Customer_Obj::createFirstNameArray() {
		//create array from given firstNames file
        ifstream infile;
        infile.open("FirstNames.txt",ifstream::in);
        assert(infile.is_open());

        int i=0;
        while(!infile.eof()) {
                string name;
                infile>>name;
                firstNames[i]=name;
                i++;
        }
}

void Customer_Obj::createLastNameArray() {
		//create array from given lastNames file
        ifstream infile;
        infile.open("LastNames.txt",ifstream::in);
        assert(infile.is_open());

        int i=0;
        while(!infile.eof()) {
                string name;
                infile>>name;
                lastNames[i] = name;
                i++;
        }
}

bool Customer_Obj::isInDeli() {
		//from given statistics randomly assign whether or not customer enters deli
        int randomNumber = randNumGen(1,5);
        if(deliChoose == false){
                      deliChoose = true;
                      if(randomNumber > 0 && randomNumber <= 2)
                                      return(inDeli = true);
                      else
                                      return(inDeli = false);
        }
        else
            return(inDeli);
        

}

bool Customer_Obj::isInSweepstakes() {
		//from given statistics randomly assign whether or not customer enters sweepstakes
        int randomNumber = randNumGen(1,4);
        if(sweepsChoose == false){
                        sweepsChoose = true;
                        if(randomNumber > 0 && randomNumber <= 3)
                                        return(true);
                        else
                                        return(false);
        }
        else
            return(inSweeps);

}

void Customer_Obj::setNumItems() {
        numItems=randNumGen(1,100);
}

int Customer_Obj::getNumItems() {
        return(numItems);
}

void Customer_Obj::setLineProcessTime(int time){
     lineProcessTime = time;
}

int Customer_Obj::getLineProcessTime(){
    return(lineProcessTime);
}

void Customer_Obj::setActionTime(int time){
     actionTime = time;
}

int Customer_Obj::getActionTime(){
    return(actionTime);
}

void Customer_Obj::setFullName(string l,string f){
        fullName = l + f;
}

string Customer_Obj::getFullName() {
        return(fullName);
}


